package yf.mall.controller.api.web;

import com.yf.annotation.IgnoreAuth;
import com.yf.response.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import yf.mall.entity.ArticleEntity;
import yf.mall.enums.ArticleStatusEnum;
import yf.mall.service.ArticleService;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/api/app/article")
@RestController
public class ApiWebArticleController {

    @Resource
    private ArticleService articleService;

    @GetMapping("/{id}")
    @IgnoreAuth
    public R index( @PathVariable Long id){
        ArticleEntity articleEntity = articleService.get(id);
        return R.ok(articleEntity);
    }

    @GetMapping("/type/{type}")
    @IgnoreAuth
    public R list(@PathVariable Integer type) {
        List<ArticleEntity> list = articleService.findByTypeAndStatus(type, ArticleStatusEnum.PUBLISH.getIndex());
        return R.ok(list);
    }

}
